﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cspl.Calculator.Library.Interface;
using Cspl.Calculator.Library.Model;

namespace Cspl.Calculator.Library
{
    public class MainCalculator
    {
        #region Private Fields
        private IBasicCalculator _calculator;
        private CalModel _data;
        #endregion

        #region Properties
        public CalModel Data
        {
            get { return _data; }
            set { _data = value; }
        }
        #endregion

        #region Constructors
        public MainCalculator()
        {
            this._calculator = new BasicCalculator();
        }
        #endregion

        #region Methods
        public int Calculate()
        {
            if (this._data != null)
            {
                if (this.Data.CalMode == CalMode.single)
                {
                    switch (this.Data.Operation)
                    {
                        case CalOperations.Add:
                            return this._calculator.Add(this.Data.IntegerValue1,
                            this.Data.IntegerValue2);

                        case CalOperations.Sub:
                            return this._calculator.Sub(this.Data.IntegerValue1,
                                this.Data.IntegerValue2);
                        case CalOperations.Mul:
                            return this._calculator.Mul(this.Data.IntegerValue1,
                                this.Data.IntegerValue2);
                        case CalOperations.Div:
                            return this._calculator.Div(this.Data.IntegerValue1,
                                this.Data.IntegerValue2);
                        default:
                            break;
                    }
                }
                else 
                {
                    return this._calculator.ComplexListOperation(this.Data.ListOfIntegerValue,this.Data.Operation);
                }
            }
            else
            {
                Console.WriteLine("There is no data to be calculated!");
            }
            return 0;
        }
        #endregion        
    }

    public enum CalOperations { Add, Mul, Div, Sub}
    public enum CalMode {single,list}
}
